<template>

	<view class="login-form">
		<view class="item">
			<view class="account">
				<text class="input-item">酒店名称</text>
				<input  data-type=""  placeholder-class="inp-palcehoder" placeholder="请输入酒店名称"
					v-model="resister.remark"></input>
			</view>
		</view>

		<view class="item">
			<view class="account">
				<text class="input-item">联系电话</text>
				<input type="number" data-type="" placeholder-class="inp-palcehoder" placeholder="请输入电话"
					v-model="resister.userPhoneNum"></input>
			</view>
		</view>


		<view class="item">
			<view class="account">
				<text class="input-item">密码</text>
				<input  data-type=""  placeholder-class="inp-palcehoder" placeholder="请输入密码"
					v-model="resister.userPassword"></input>
			</view>
		</view>
		<view class="item">
			<view class="account">
				<text class="input-item">地址</text>
				<input data-type="" placeholder-class="inp-palcehoder" placeholder="请输入地址"
					v-model="resister.userAddress"></input>
			</view>
		</view>
		<view class="item">
			<view class="account">
				<text class="input-item">联系人</text>
				<input data-type="" placeholder-class="inp-palcehoder" placeholder="请输入联系人"
					v-model="resister.userName"></input>
			</view>
		</view>
		<view>
			<button class="authorized-btn" @click="toLogin">确定</button>
			<button class="to-idx-btn" @click="toLoginCancel">取消</button>
		</view>

	</view>

</template>

<script>
	export default {
		data() {
			return {
				active: true,
				wxOpenId: '',
				resister: {
					remark: '', //  备注
					userName: '',
					userPassword: '',
					userPhoneNum: '',
          userAddress:'',

				}
			}
		},
		onLaunch() {
			wx.login({
				success(res) {
					if (res.code) {
						//发起网络请求
						wx.request({
							url: 'https://api.weixin.qq.com/sns/jscode2session',
							data: {
								// appid: 'wx9daae765f132132e',
								appid: 'wx3452301d2612b1d0',

								secret: '2a0b2cbf6787ad53b679a5186300144f',
								js_code: res.code,
								grant_type: 'authorization_code'
							},
							success: (res) => {
								// console.log( res )
								this.wxOpenId = res.data.openid
							}
						})
					} else {
						console.log(res.errMsg)
					}
				}
			})

		},
		methods: {
			//登录
			toLogin() {
				const date = new Date();
				const isoDate = date.toISOString();
				var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; //11位手机号码正则
				if (!reg_tel.test(this.resister.userPhoneNum)) {
					return uni.showModal({
						title: '手机号码有误重新输入',
						duration: 2000
					});
				}
				console.log('请求  user/insertOrUpdateHotelUser', {
					"createBy": '',
					"delFlag": 0,
					"hotelId": '',
					'updateBy': '',
					"userId": '',
					"userStatus": 0,
					'userType': 2,
					"createTime": isoDate,
					"updateTime": isoDate,
					"wxOpenId": this.wxOpenId,
					'createTime': '',
					"remark": this.resister.remark + " " +this.resister.userName + " " + this.resister.userAddress,
					"userName": this.resister.userName,
					"userPassword": this.resister.userPassword,
					"userPhoneNum": this.resister.userPhoneNum,
					"code": 100000000,
				})
				this.$request.post('user/insertOrUpdateHotelUser', {
					"createBy": '',
					"delFlag": 0,
					"hotelId": '',
					'updateBy': '',
					"userId": '',
					"userStatus": 0,
					'userType': 2,
					"createTime": isoDate,
					"updateTime": isoDate,
					"wxOpenId": this.wxOpenId,
					'createTime': '',
					"remark": this.resister.remark + ' ' +this.resister.userName + " " + this.resister.userAddress,
					"userName": this.resister.userName,
					"userPassword": this.resister.userPassword,
					"userPhoneNum": this.resister.userPhoneNum,
					"code": 100000000,
				}).then((res) => {
					console.log("收到注册消息回调", res);
					if (res.code !== 100000000) {
						return wx.showModal({
							title: "温馨提示",
							content: res.msg || '系统异常，请稍后重试',
							confirmColor: '#07C160',
							showCancel: false,
						});
					} else {
						wx.showModal({
							title: "温馨提示",
							content: '恭喜!注册成功!',
							confirmColor: '#07C160',
							showCancel: false,
							success: function() {
								uni.navigateTo({
									url: '/pages/login/login/login'
								})
							}
						});
						//说明是欧克的
					}
				})
				//     uni.request({
				//       // url:'https://xingzhiyuan.work:8081/user/insertOrUpdateHotelUser' ,
				// url:'https://xingzhiyuanst.top/user/insertOrUpdateHotelUser' ,
				// // https://xingzhiyuanst.top
				//       method:'POST',
				//       data:{
				//           "createBy":'',
				//           "delFlag":0,
				//           "hotelId":'',
				//           'updateBy':'',
				//           "userId":'',
				//           "userStatus":0,
				//           'userType':2,
				//           "createTime":isoDate,
				//           "updateTime":isoDate,
				//           "wxOpenId":this.wxOpenId ,
				//           'createTime':'',
				//           "remark": this.resister.remark,
				//           "userName": this.resister.userName,
				//           "userPassword": this.resister.userPassword,
				//           "userPhoneNum": this.resister.userPhoneNum,
				//           "code": 100000000,
				//           },
				//           success(res) {
				//               if ( res.data.code !== 100000000)  { 
				//               return  wx.showModal({
				//                         title: "温馨提示",
				//                         content: res.data.msg || '系统异常，请稍后重试',
				//                         confirmColor: '#07C160',
				//                         showCancel: false,
				//                     }); }
				//                     //说明是欧克的
				//                     uni.navigateTo({
				//                       url:'/pages/login/login/login'
				//                     })
				//             }

				//     })


			},
			toLoginCancel() {
				uni.navigateTo({
					url: '/pages/login/login/login'
				})
			}

		}
	}
</script>

<style scoped lang="scss">
	view.msg {
		font-size: 24rpx;
		color: #666;
		width: 100%;
		text-align: center;
		margin-top: 10rpx;
	}

	view.title {
		font-size: 28rpx;
		color: #333;
		width: 100%;
		text-align: center;
		margin: 20rpx 0;
	}

	button {
		margin-top: 30rpx;
		width: 450rpx;
		height: 70rpx;
		line-height: 70rpx;
		font-size: 30rpx;
		color: #fff;
		background: #eb2444;
		border: 2rpx solid #eb2444;
	}

	page {
		background: #fff;
		height: 100%;
	}

	.login-form {
		width: 90%;
		margin: 0 auto;
		margin-top: 50%;
		transform: translateY(-30%);
	}

	.authorized-btn {
		width: 100%;
		margin: 0 auto;
		text-align: center;
		background-color: #0ab906;
		border: 1rpx solid #0ab906;
		color: #fff;
		border-radius: 6rpx;
		font-size: 26rpx;
		margin-top: 60rpx;
	}

	.to-idx-btn {
		width: 100%;
		margin: 0 auto;
		text-align: center;
		background-color: #eeeeee;
		border: 1rpx solid #eeeeee;
		color: #333;
		border-radius: 6rpx;
		font-size: 26rpx;
		margin-top: 30rpx;
	}

	.form-title {
		width: 100%;
		margin-bottom: 50rpx;
		font-size: 32rpx;
		text-align: center;
		color: #00a0e9;
	}

	.item {
		display: block;
		margin-bottom: 30rpx;
	}

	.account {
		display: flex;
		background: #f8f8f8;
		padding: 15rpx;
		box-sizing: border-box;
		font-size: 26rpx;
		align-items: center;
	}

	.account input {
		padding-left: 20rpx;
		width: 75%;
	}

	.inp-palcehoder {
		font-size: 26rpx;
	}

	.account input.int-yzm {
		width: 410rpx;
		padding-right: 10rpx;
		box-sizing: border-box;
	}

	.input-btn {
		width: 152rpx;
		font-size: 26rpx;
		color: #00a0ea;
		text-align: center;
	}

	button::after {
		border: 0 !important;
	}

	.input-item {
		width: 130rpx
	}
</style>